-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unique_id field to product #47364
Conversation
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
a36a2b4
to
3d28f75
Compare
Hi @louwie17, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job @nathanss! This is testing well here and the code LGTM.
However, I would like to ask a couple of questions. After answering them, I think this PR will be ready to go.
- Could the
unique_id
be repeated? I mean, now it is possible to have them duplicated, but I was wondering if that was expected. - The SKU will continue being unique, right? Maybe we can add a comment explaining that briefly because the naming is not very intuitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the unique_id be repeated? I mean, now it is possible to have them duplicated, but I was wondering if that was expected.
This does seem like a critical piece we want to implement from the start, and something that is easier to implement now and than later on revert, versus the other way around.
I would say given this is a unique id, we should have it act similar as a SKU and not allow duplicates across products.
Did any of this come up in the discussions? or P2 conversations?
'type' => 'string', | ||
'context' => array( 'view', 'edit' ), | ||
), | ||
'unique_id' => array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm should the description
here for unique_id
be: 'GTIN, UPC, EAN or ISBN'
?
And we keep 'Unique identifier.'
for the sku
field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with renaming the unique_id
field, but I think we should avoid saying that sku
is an 'Unique identifier', since we're introducing a new field with this name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clarification: sku
is unique at the store level vs. the new field shall hold a globally unique identifier such as GTIN
.
Hence, the proposed new unique_id
would also be unique at the store level.
Maybe calling it global_unique_id
could be more explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. I will rename it
I agree that we should avoid duplications. |
Size Change: +37 B (0%) Total Size: 2.49 MB |
c9f1144
to
ca02069
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @nathanss, it tested well!
I left a couple small comments, but for the rest this looks great!
/** | ||
* Get Unique ID. | ||
* | ||
* @since 9.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be updated to 9.1 as well
@@ -535,7 +541,12 @@ public function get_item_schema() { | |||
'readonly' => true, | |||
), | |||
'sku' => array( | |||
'description' => __( 'Unique identifier.', 'woocommerce' ), | |||
'description' => __( 'SKU.', 'woocommerce' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still keep this as 'Unique identifier.'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer keeping it like this, to avoid confusion with the new field, though I don't think this description is a big deal. I'll update it to Stock Keeping Unit, is that OK?
@@ -987,7 +992,12 @@ public function get_item_schema() { | |||
'context' => array( 'view', 'edit' ), | |||
), | |||
'sku' => array( | |||
'description' => __( 'Unique identifier.', 'woocommerce' ), | |||
'description' => __( 'SKU.', 'woocommerce' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above.
8544974
to
f4cc4a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @nathanss , I tested this and it looks good to me!
I have two questions:
- The new field is only available on the new product editor, correct?
- Will the
global_unique_id
be populated to the REST API?
Yes, currently, that is correct.
It is added to the REST API. The new product editor consumes the REST API, so it will be available there immediately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the API description updates using Stock Keeping Unit.
seems good with me.
I tested this again and it seems to test well, nice work, I also noticed that the wcadmin_product_add_publish
track includes the global_unique_id
id 👍
* Add unique_id field to product * Fix documentation * Fix wrong comment * Update description * Add unique_id for variations * Update lint * Update tests * Add changelog * Update variations unit test * Add unique_id to wc_product_meta_lookup * Add unique_id methods to cpt interface * Add new methods for unique_id and add it to lookup table * Add unique_id functions to product functions * Throw error when unique_id is duplicated * Handle error message for unique_id on the front-end * Add changelog * Rename unique_id description in REST API * Fix lint issues * Add unique_id tracking for product publish * Rename to 'global_unique_id' * Fix lint * Fix lint * Bump documentation version * Update controller description of fields
* Add unique_id field to product * Fix documentation * Fix wrong comment * Update description * Add unique_id for variations * Update lint * Update tests * Add changelog * Update variations unit test * Add unique_id to wc_product_meta_lookup * Add unique_id methods to cpt interface * Add new methods for unique_id and add it to lookup table * Add unique_id functions to product functions * Throw error when unique_id is duplicated * Handle error message for unique_id on the front-end * Add changelog * Rename unique_id description in REST API * Fix lint issues * Add unique_id tracking for product publish * Rename to 'global_unique_id' * Fix lint * Fix lint * Bump documentation version * Update controller description of fields
* Add unique_id field to product * Fix documentation * Fix wrong comment * Update description * Add unique_id for variations * Update lint * Update tests * Add changelog * Update variations unit test * Add unique_id to wc_product_meta_lookup * Add unique_id methods to cpt interface * Add new methods for unique_id and add it to lookup table * Add unique_id functions to product functions * Throw error when unique_id is duplicated * Handle error message for unique_id on the front-end * Add changelog * Rename unique_id description in REST API * Fix lint issues * Add unique_id tracking for product publish * Rename to 'global_unique_id' * Fix lint * Fix lint * Bump documentation version * Update controller description of fields
Submission Review Guidelines:
Changes proposed in this Pull Request:
Adds a new "unique id" field to the new product editor. The field accepts any type of input, at least for now.
Closes #41816
Closes #39577
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Changelog entry
Significance
Type
Message
Comment